package com.bawei.lib_common.base.utils

import android.app.Activity
import android.graphics.Color
import android.transition.TransitionInflater
import android.view.View
import android.view.Window
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.RecyclerView

/**
 *@author：lxy
 *@decription:
 *@time：2025/7/2
 */
object MemoryMonitor {
    fun getMemoryInfo(): String {
        val runtime = Runtime.getRuntime()
        val usedMemory = runtime.totalMemory() - runtime.freeMemory()
        val maxMemory = runtime.maxMemory()
        return "已用内存: ${usedMemory / 1024 / 1024}MB, 最大内存: ${maxMemory / 1024 / 1024}MB"
    }
}


class PageTransitionManager {
    fun setupPageTransitions(activity: Activity) {
        activity.window.requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS)
        activity.window.sharedElementEnterTransition = TransitionInflater.from(activity)
            .inflateTransition(android.R.transition.move)
    }
}


class RecyclerViewAnimator {
    fun addItemAnimations(recyclerView: RecyclerView) {
        recyclerView.itemAnimator = object : DefaultItemAnimator() {
            override fun animateAdd(holder: RecyclerView.ViewHolder): Boolean {
                holder.itemView.alpha = 0f
                holder.itemView.translationY = 50f

                holder.itemView.animate()
                    .alpha(1f)
                    .translationY(0f)
                    .setDuration(300)
                    .start()

                return true
            }
        }
    }
}

